//
//  FSHistoryViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/13.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSHistoryViewController.h"
#import "GDataDefines.h"

@interface FSHistoryViewController ()

@property(nonatomic,strong)FSHistoryModel * historyModel;
@property(nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation FSHistoryViewController

-(NSMutableArray*)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.view.backgroundColor = [UIColor whiteColor];    
    self.title = @"流转历史";
    self.tableView.hidden = YES;
    [self loadData];

}


#pragma mark 加载网络数据
-(void)loadData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unId":self.fileId},@{@"userId":userId}];
    [HttpTools postWithURL:KexchgeneralURL arrays:array method:KroamHistoryMethod success:^(id JSON) {
        self.tableView.hidden = NO;
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [self getDetailModel:JSON];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
    
}

-(void)getDetailModel:(NSString*)dataString{
    NSData * data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    //获取根节点（Users）
    GDataXMLElement *rootElement = [doc rootElement];
    //获取根节点下的节点（User）
    
    NSArray *arrData= [rootElement elementsForName:@"数据"];
    for (GDataXMLElement *ser in arrData) {
        NSArray *serr = [ser elementsForName:@"数据要素"];
        for (GDataXMLElement *data in serr) {
            FSHistoryModel * model = [[FSHistoryModel alloc]init];
            GDataXMLElement *filetID = [[data elementsForName:@"序号"] objectAtIndex:0];
            model.number = [filetID stringValue];
            
            GDataXMLElement *setp = [[data elementsForName:@"处理步骤"] objectAtIndex:0];
            model.setp = [setp stringValue];
            
            GDataXMLElement  * worker = [[data elementsForName:@"处理人"] objectAtIndex:0];
            model.worker = [worker stringValue];
            
            GDataXMLElement * receive = [[data elementsForName:@"接收时间"] objectAtIndex:0];
            model.receiveDate = [receive stringValue];
            
            
            GDataXMLElement *send = [[data elementsForName:@"业务流向"] objectAtIndex:0];
            model.sendto = [send stringValue];
            
            GDataXMLElement *complete = [[data elementsForName:@"完成时间"] objectAtIndex:0];
            model.completeTime = [complete stringValue];
            
            GDataXMLElement *status = [[data elementsForName:@"状态"] objectAtIndex:0];
            model.status = [status stringValue];
            
            [self.dataArray addObject:model];
            
        }
        
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

#pragma mark UITbableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FSHistoryCell * cell = [FSHistoryCell  cellWihtTableView:tableView];
    FSHistoryModel * model = self.dataArray[indexPath.row];
    cell.historyModel = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 246;
}



@end










